package com.lsa.helpers.tree;

public class TreeWalker<T>{
    protected ITreeVisitor<T> visitor;
    
    public TreeWalker(ITreeVisitor<T> visitor){
        this.visitor = visitor;
    }

    public Object walk(ITreeNode<T> node) throws Exception{
        if (visitor != null){
            visitor.visit(node);
        }
        
        for( ITreeNode<T> childNode : node.getChildren() ){
        	if (childNode != null) walk(childNode);
        }
        return null;
    }
}
